package com.cskaoyan.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author: lds
 * @clsss: CustomSessionManager
 */
public class CustomSessionManager extends DefaultWebSessionManager {
    @Override
    protected Serializable getSessionId(ServletRequest srequest, ServletResponse sresponse) {
        HttpServletRequest request = (HttpServletRequest) srequest;
        String requestURI = request.getRequestURI();
        System.out.println("requestURI"+requestURI);
        String sessionId = null;
        if (requestURI.equals("/logout/kickout")){
           sessionId = request.getParameter("token");

        }else {
            //   X-cskaoyan-mall-Admin-Token

             sessionId = request.getHeader("X-cskaoyan-mall-Admin-Token");
        }


        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        String sessionId2 = request.getHeader("X-Litemall-Token");
        if (sessionId2 != null && !"".equals(sessionId2)) {
            return sessionId2;
        }
        return super.getSessionId(srequest, sresponse);

    }
}
